package com.yuneec.fly.presenters;


import android.os.SystemClock;

import com.yuneec.fly.DroneApplication;
import com.yuneec.fly.GlobalParams;
import com.yuneec.fly.R;
import com.yuneec.fly.dialogs.BaseDialogFragment;
import com.yuneec.fly.events.EventBusFactory;
import com.yuneec.fly.events.uiEvent.ExitEvent;
import com.yuneec.fly.utils.DialogHelper;

/**
 * Created by jw.gu on 2016/6/22.
 */
public class MainActivityPresenter extends BasePresenter {

    public void exitCheck() {
        if (GlobalParams.getMissionStaus() != GlobalParams.MissionStatus.NONE && SystemClock.elapsedRealtime() - GlobalParams.lastDroneFeedbackTime < 15000) {
            DialogHelper.showWarningDialog(GlobalParams.fragmentManager, DroneApplication.getApplication().getString(R.string.exit_mission_running));
        } else {
            DialogHelper.showConfirmDialog(GlobalParams.fragmentManager, DroneApplication.getApplication().getString(R.string.exit_confirm), new BaseDialogFragment.OnConfirmListener() {
                @Override
                public void onConfirm(BaseDialogFragment dialogFragment) {
                    dialogFragment.dismiss();
                    EventBusFactory.getUiBus().post(new ExitEvent());
                }
            });
        }
    }
}
